import { AxiosResponse } from 'axios'
import $axios, { Result } from '@/plugins/axios'

/**
 * 查询数据字典
 * @param parent parent为0，表示查询所有
 */
export async function getDictionary(
  parent: string = '0',
): Promise<AxiosResponse<Result>> {
  return await $axios.get(
    `/supervision-api/dictionaryEntriesController/getDictionaryEntriesByType/${parent}`,
  )
}

/**
 * 新增/修改数据字典
 * @param data 数据字典信息
 */
export async function addOrUpdateDictionaryEntries(
  data: any,
): Promise<AxiosResponse<Result>> {
  return await $axios.post(
    '/supervision-api/dictionaryEntriesController/addOrUpdateDictionaryEntries',
    data,
  )
}

/**
 * 删除数据字典
 * @param id 数据字典id
 */
export async function deleteDictionaryEntries(
  id: number,
): Promise<AxiosResponse<Result>> {
  return await $axios.delete(
    `/supervision-api/dictionaryEntriesController/deleteDictionaryEntries/${id}`,
  )
}
